package com.tansun.easycare.rule.ruletest.service.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.tansun.easycare.rule.common.model.RuleDataCollention;
import com.tansun.easycare.rule.common.service.impl.RuleBaseServiceImpl;
import com.tansun.easycare.rule.exception.BizException;
import com.tansun.easycare.rule.ruletest.dao.RuleTestItemDao;
import com.tansun.easycare.rule.ruletest.entity.RuleTestItem;
import com.tansun.easycare.rule.ruletest.service.RuleTestItemService;

@Service
public class RuleTestItemServiceImpl extends RuleBaseServiceImpl<RuleTestItemDao, RuleTestItem> implements RuleTestItemService {

    @Override
    public void deleteByTestId(Map<String, Object> map) throws BizException {
        this.dao.deleteByTestId(map);

    }
    
    public void insertBatch(List<RuleTestItem> list) throws BizException {
        if (list == null || list.size() == 0)
            return;
        for (RuleTestItem bo : list) {
            if (bo.getIsNewRecord()) {
                bo.preInsert();
            } else {
                bo.preUpdate();
            }


        }
        try {
            RuleDataCollention<RuleTestItem> ruleData = new RuleDataCollention<RuleTestItem>();
            List<RuleTestItem>  tlist  = new  ArrayList<>();
            int  i =0;
            for (RuleTestItem bo : list) {
            	i++;
            	tlist.add(bo);
            	if (i==50) {
            		   ruleData.setList(tlist);
                       this.dao.insertBatch(ruleData);
                       tlist.clear();
                       i=0;
            	}
           
            }
            if (tlist.size()>0) {
     		   ruleData.setList(tlist);
               this.dao.insertBatch(ruleData);
            }
        } catch (Exception e) {
            throw new BizException(e, "");
        }

    }


}
